﻿
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<div id="appNewsCategory" style="margin:2px;padding:2px;">
    <el-form inline label-position="right" label-width="70px" class="query-form">
        <el-form-item>
            <el-button type="success" size="small" @@click="newsCategoryEdit(null)" v-show="pageButtons.includes('addnewscategory')">新增</el-button>
        </el-form-item>
    </el-form>
    <el-table :data="tableData" row-key="id" stripe border style="width:100%" size="mini"  >
        <el-table-column type="index" width="50" align="center"></el-table-column>
        <el-table-column prop="categoryName" label="分类名称" width="400"></el-table-column> 
        <el-table-column prop="orderIndex" label="排序" width="100"></el-table-column> 
        <el-table-column label="状态" width="100" align="center">
            <template slot-scope="scope">
                <el-button type="success" round size="mini" v-if="scope.row.enabled==true">{{scope.row.enabled === false ? '禁用' : '启用'}}</el-button>
                <el-button type="danger" round size="mini" v-if="scope.row.enabled==false">{{scope.row.enabled === false ? '禁用' : '启用'}}</el-button>
            </template>
        </el-table-column> 
        <el-table-column fixed="right" label="操作" width="350" align="center">
            <template slot-scope="scope">
                <el-button :type="scope.row.enabled === true?'danger':'success'" @@click="SetEnabled(scope.row)" size="mini" v-show="pageButtons.includes('newscategory_setenabled')">
                    <span>{{scope.row.enabled === true ? '禁用' : '启用'}}</span>
                </el-button>
                <el-button type="primary" size="mini" @@click="newsCategoryEdit(scope.row )" v-show="pageButtons.includes('editnewscategory')">修改</el-button> 
            </template>
        </el-table-column>
    </el-table>
</div>
<style>
    .el-checkbox {
        margin-bottom: 10px !important;
    }

    .chktext {
        white-space: normal;
        word-break: break-all;
        width: 150px;
    }
</style>
<script>
    function refreshFromChild() {
        vueRole.GetNewsCategoryList();
    }

    var vueRole = new Vue({
        el: '#appNewsCategory',
        data() {
            return {
                pageButtons: [],
 
                total: 0,
                tableData: [], 
                 

                selectRoleId:0,
            }
        },
        created(){
            var _this = this;
            this.GetNewsCategoryList();

            _this.$getMenuButtons();
        },
        methods: {

            newsCategoryEdit(row) {
                var id = 0;
                if (row) id = row.id;
                this.$addTab(id, id == 0 ? "新增资讯分类" : "修改资讯分类", "../newsCategory/edit?id=" + id);
            },
            tableRowClassName({ row, rowIndex }) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            }, 
            handleClick(row) {
                console.log(row);
            },
            GetNewsCategoryList() {
                  var _this = this;
                 _this.$get("@Url.Action("GetNewsCategoryList", "NewsCategory")" ).then((response) => {
                        _this.tableData = response;
                  }).catch((error) => {
                  });
            },
            SetEnabled(row) {
                var _this = this;
                var msg = "";
                if (row.enabled == true) {
                    msg = "确认设置禁用吗？";
                } else {
                    msg = "确认设置启用吗？";
                }
                _this.$confirm(msg, '提示', {})
                    .then(() => {
                        _this.$post("@Url.Action("SetEnabled", "NewsCategory")?CategoryId=" + row.id + "&enabled=" + !(row.enabled)).then((res) => {
                          _this.$success(res.message, function () {
                              if(res.success)
                                  _this.GetNewsCategoryList();
                          });


                          }).catch((error) => {
                          });
                    })

            },
            newsCategoryDelete: function (row) {
                var _this = this;
                _this.$confirm('确认删除该数据吗?', '提示', {})
                    .then(() => {
                         _this.$post("@Url.Action("DeleteNewsCategory", "NewsCategory")?Id="+row.id  ).then((res) => {
                              _this.$success(res.message, function () {
                                  if(res.success)
                                      _this.GetNewsCategoryList();
                              });
                          }).catch((error) => {
                          });
                    })

            }
        }
    });
</script>